package com.ai.deepseek.controller;

import com.ai.deepseek.entity.MessageReq;
import com.ai.deepseek.forest.MyHttpClient;
import groovy.util.logging.Slf4j;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.openai.api.OpenAiApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.configurationprocessor.json.JSONException;
import org.springframework.boot.configurationprocessor.json.JSONObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description :
 * @Author : Bruce Lee
 * @CreateTime : 2025/2/12
 */


@RestController
@RequestMapping("/ai")
@Slf4j
public class ChatController {

//    @Autowired
//    private MyHttpClient myHttpClient;

//    @Autowired
//    private RestTemplate restTemplate;

    private ChatClient chatClient;


    private OpenAiApi openAiApi;

    public ChatController(ChatClient.Builder chatClientBuilder) {
        this.chatClient = chatClientBuilder.build();
    }

    @GetMapping("/chat")
    public String chat(@RequestParam("prompt") String prompt) {
        return this.chatClient.prompt(prompt).call().content();
    }

//    @GetMapping("/chat2")
//    public String chat2() throws JSONException {
//        MessageReq messageReq = new MessageReq();
//        messageReq.setModel("deepseek-r1");
//        JSONObject jsonObject = new JSONObject();
//        jsonObject.put("role", "user");
//        jsonObject.put("content", "什么是AI大模型");
//        List<JSONObject> jsonObjects = new ArrayList<>();
//        jsonObjects.add(jsonObject);
//        messageReq.setMessages(jsonObjects);
//
//        return this.myHttpClient.chat(messageReq);
//    }


}
